package com.jinyuan.options.login;

import com.jinyuan.R;
import com.jinyuan.options.SlidingMenuControlActivity;
import com.jinyuan.view.loading.LoadingAnimations;

import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.widget.RelativeLayout;
import android.app.Activity;
import android.content.Intent;

public class LoadingActivity extends Activity {

	private boolean isFinish = false;
	private RelativeLayout loading_RelativeLayout;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.loading);
		loading_RelativeLayout = (RelativeLayout) findViewById(R.id.loading_RelativeLayout);
		new Handler().post(new Runnable() {

			@Override
			public void run() {
				LoadingAnimations.startAnimations(loading_RelativeLayout, 3000);
			}
		});
		intentToMain();
	}
	
	private void intentToMain() {
		if (!isFinish) {
			new Handler().postDelayed(new Runnable() {
				@Override
				public void run() {
					Intent mainIntent = new Intent(LoadingActivity.this,
							SlidingMenuControlActivity.class);
					mainIntent.putExtras(getIntent());
					startActivityForResult(mainIntent, 10);
					overridePendingTransition(R.anim.anim_fromright_toup6,
							R.anim.anim_down_toleft6);
					finish();
				}
			}, 6000);
		}
	}

	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
			if (event.getAction() == KeyEvent.ACTION_DOWN
					&& event.getRepeatCount() == 0) {
				isFinish = true;
				finish();
				return true;
			} else {
				return false;
			}
		} else {
			return super.dispatchKeyEvent(event);
		}
	}

}
